/************************************************************************
 * <br>
 * <ul>
 * <li>版权所有：唐山弘川科技有限公司 2009－2020</li>
 * <li>创建日期：2009-8-14</li>
 * <li>初始作者：刘川</li>
 * </ul>
 * <ul>
 * <b>修订历史</b>
 * <li>1、</li>
 * </ul>
 ***********************************************************************/
/*package com.hy.enterprise.framework.service.business ;

import java.util.List;

import javax.management.RuntimeErrorException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Component;
//import org.jboss.seam.Component;


import com.extjs.gxt.ui.client.data.BaseModel;
import com.extjs.gxt.ui.client.data.ModelData;
import com.hy.enterprise.framework.jpa.core.dao.IDao;
import com.hy.enterprise.framework.jpa.core.entity.Persistable;
import com.hy.enterprise.framework.jpa.core.util.GenericsUtils;
import com.hy.enterprise.framework.jpa.core.util.MySpringUtil;
import com.hy.enterprise.framework.lang.IHierarchialbe;
import com.hy.enterprise.framework.persistence.api.annotation.DaoA;
import com.hy.enterprise.framework.service.ServiceException;
import com.hy.enterprise.framework.service.seam.AbstractSeamLibraService;
import com.hy.enterprise.framework.util.LibraUtil;
import com.hy.enterprise.framework.util.jpa.JpaUtil;
import com.hy.enterprise.framework.util.lang.AnnotationUtil;
import com.hy.enterprise.framework.util.logger.SeamLoggerUtil;
import com.hy.enterprise.framework.util.seam.SeamUtil;
import com.hy.mydesktop.client.component.meta.GridPagingLoadResultModel;
import com.hy.mydesktop.shared.persistence.domain.gxt.MyBaseModel;
import com.hy.mydesktop.shared.persistence.domain.gxt.constant.ComponentMetaDataConstants;
import com.hy.mydesktop.shared.persistence.domain.gxt.constant.MetaDataConstants;

*//**
 * <ul>
 * <li>设计作者：刘川</li>
 * <li>设计日期：2009-8-14</li>
 * <li>设计时间：上午11:11:24</li>
 * <li>设计目的：</li>
 * </ul>
 * <ul>
 * <b>修订历史</b>
 * <li>1、</li>
 * </ul>
 *//*
//public class AbstractBusinessService < BusinessBean extends IServiceBusinessBean >  extends AbstractSeamLibraService implements  IBusinessService < BusinessBean >
//@Component("abstractBusinessService")
//public  class AbstractBusinessService<ServiceDao extends IDao >   extends AbstractSeamLibraService implements  IBusinessService 
public   class AbstractBusinessService<ServiceDao extends IDao>    implements  IBusinessService 
//public   class AbstractBusinessService<ServiceDao extends IDao,PersistentEntity extends Persistable  >    implements  IBusinessService <ServiceDao ,PersistentEntity >
{
	*//**
	 * 日志记录器
	 *//*
	
	
	private static Log logger = LogFactory.getLog(AbstractBusinessService.class);

	private static final long	serialVersionUID	=
	                                                  8240494730203524975L ;

	private Class<ServiceDao> serviceDao = GenericsUtils.getSuperClassGenricType(this.getClass());
	//private Class<ServiceDao> entityClass = null;

	*//**
	 * 构造函数
	 *//*
	public AbstractBusinessService ( )
	{
		super ( ) ;
	}

	*//**
	 * <ul>
	 * <li>设计作者：刘川</li>
	 * <li>设计日期：2009-8-14</li>
	 * <li>设计时间：上午11:18:00</li>
	 * <li>设计目的：根据指定业务Bean，获取操作该业务Bean的数据访问对象</li>
	 * </ul>
	 * <ul>
	 * <b>修订历史</b>
	 * <li>1、</li>
	 * </ul>
	 * 
	 * @param <T>
	 * @param businessBeanClass
	 * @return
	 *//*
	@ SuppressWarnings ( "unchecked" )
	public <T extends IServiceBusinessBean> IDao<T> getDao(
			Class<T> businessBeanClass) {
		//TODO 获取ImplementsBy的实体类名称
		Class<?> entityClass = LibraUtil.getImplementClass(businessBeanClass);
		SeamLoggerUtil.debug(AbstractBusinessService.logger,
				"AbstractBusinessService.getDao()方法中所获取的实体类类型为：" + entityClass);
		if (JpaUtil.isEntity(entityClass)) {
			if (AnnotationUtil
					.isClassAnnotationPresent(entityClass, DaoA.class)) {
				Class<?> daoClass = AnnotationUtil.getAnnotation(entityClass,
						DaoA.class).value();
				daoClass = LibraUtil.getImplementClass(daoClass);
				SeamLoggerUtil.debug(AbstractBusinessService.logger,
						"AbstractBusinessService.getDao()方法所需要创建的数据访问对象类型为："
								+ daoClass);
				if (SeamUtil.isSeamComponent(daoClass)) {
//					return (IDao<T>) Component.getInstance(daoClass, true);
					return (IDao<T>) MySpringUtil.getSpringComponent(daoClass);
				} else {
					IDao<T> dao = null;
					try {

						dao = (IDao<T>) daoClass.newInstance();
						return dao;
					} catch (InstantiationException instantiationException) {
						SeamLoggerUtil.error(AbstractBusinessService.logger,
								instantiationException);
						throw new ServiceException("在创建DAO实例时发生错误",
								instantiationException);
					} catch (IllegalAccessException illegalAccessException) {
						SeamLoggerUtil.error(AbstractBusinessService.logger,
								illegalAccessException);
						throw new ServiceException("在创建DAO实例时发生错误",
								illegalAccessException);
					}
				}
			} else {
				SeamLoggerUtil
						.debug(AbstractBusinessService.logger,
								"为AbstractBusinessService.getDao()方法所传递的参数：["
										+ businessBeanClass
										+ "]并没有标注：[com.hy.enterprise.framework.persistence.api.annotation.DaoA]注解");
				return null;
			}
		} else {
			SeamLoggerUtil.debug(AbstractBusinessService.logger,
					"为AbstractBusinessService.getDao()方法所传递的参数：["
							+ businessBeanClass + "]并不是实体类类型，因此无法获取所对应的DAO");
			return null;
		}
	}

	*//**
	 * <ul>
	 * <li>设计作者：刘川</li>
	 * <li>设计日期：2009-8-14</li>
	 * <li>设计时间：上午11:16:29</li>
	 * <li>设计目的：判断指定业务Bean类型是否为层次型结构</li>
	 * </ul>
	 * <ul>
	 * <b>修订历史</b>
	 * <li>1、</li>
	 * </ul>
	 * 
	 * @param serviceBusinessBean
	 * @return
	 *//*
	protected boolean checkHierarchiable (
	                                       IServiceBusinessBean serviceBusinessBean )
	{
		if ( ( null == serviceBusinessBean )
		     || ( ! ( ( serviceBusinessBean instanceof IHierarchialbe ) ) ) )
		{
			return false ;
		}
		else
		{
			return true ;
		}
	}

	

	@Override
	public  boolean submitPersistentEntities(List list ) {
		String serviceDaoName= serviceDao.getSimpleName();
		String springComponentName = 
			serviceDaoName.substring(0, 1).toLowerCase()+serviceDaoName.substring(1);
		IDao iDao = (IDao) MySpringUtil.getSpringComponent(springComponentName);
		return iDao.submitPersistentEntities(list);
		
		//return false;
	}
	
	@Override
	public  GridPagingLoadResultModel getPageOfPersistentEntities(ModelData[] modelDatas) {
		int offset = -1;
		int limit = -1;
		if (modelDatas!=null&&modelDatas.length==1) {
			if (modelDatas[0].get(ComponentMetaDataConstants.OFFSET)!=null&&
					modelDatas[0].get(ComponentMetaDataConstants.LIMIT)!=null) {
				offset=modelDatas[0].get(ComponentMetaDataConstants.OFFSET);
				limit=modelDatas[0].get(ComponentMetaDataConstants.LIMIT);
			} else {

			}
		}else {
			throw new RuntimeException("22222222222222222");
		}
		String serviceDaoName= serviceDao.getSimpleName();
		String springComponentName = 
			serviceDaoName.substring(0, 1).toLowerCase()+serviceDaoName.substring(1);
		IDao iDao = (IDao) MySpringUtil.getSpringComponent(springComponentName);
		//logger.debug("offset:"+offset);
		//logger.debug("limit:"+limit);
		List<MyBaseModel> list = iDao.find(offset, limit);
		limit =iDao.count();
		GridPagingLoadResultModel gridPagingLoadResultModel=new GridPagingLoadResultModel();
		gridPagingLoadResultModel.setDataList(list);
		gridPagingLoadResultModel.setOffset(offset);
		gridPagingLoadResultModel.setTotalLength(limit);
		
		return gridPagingLoadResultModel;
	}
	
	@Override
	public MyBaseModel findByIdentifier(List	baseModels){
		String identifier = null;
		if(baseModels.size()==1){
			identifier =((BaseModel)baseModels.get(0)).get(MetaDataConstants.IDENTIFIER);
		}
		
		
		return this.findByIdentifier(identifier);
	}
	@Override
	public MyBaseModel findByIdentifier(String identifier){
		String serviceDaoName= serviceDao.getSimpleName();
		String springComponentName = 
			serviceDaoName.substring(0, 1).toLowerCase()+serviceDaoName.substring(1);
		IDao iDao = (IDao) MySpringUtil.getSpringComponent(springComponentName);
		//entityClass =GenericsUtils.getSuperClassGenricType(this.getClass(),1);
		
		return (MyBaseModel)iDao.findByIdentifier(identifier);
	}

	@Override
	public  List<MyBaseModel> getAllPersistentEntities() {
		
		String serviceDaoName= serviceDao.getSimpleName();
		String springComponentName = 
			serviceDaoName.substring(0, 1).toLowerCase()+serviceDaoName.substring(1);
		IDao iDao = (IDao) MySpringUtil.getSpringComponent(springComponentName);

		return iDao.find();
		
		//return false;
	}
	@Override
	public  List<MyBaseModel> getPageOfPersistentEntities(ModelData[] modelDatas) {
		int offset = -1;
		int limit = -1;
		if (modelDatas!=null&&modelDatas.length==1) {
			if (modelDatas[0].get(ComponentMetaDataConstants.OFFSET)!=null&&
					modelDatas[0].get(ComponentMetaDataConstants.LIMIT)!=null) {
				offset=modelDatas[0].get(ComponentMetaDataConstants.OFFSET);
				limit=modelDatas[0].get(ComponentMetaDataConstants.LIMIT);
			} else {

			}
		}else {
			throw new RuntimeException("22222222222222222");
		}
		String serviceDaoName= serviceDao.getSimpleName();
		String springComponentName = 
			serviceDaoName.substring(0, 1).toLowerCase()+serviceDaoName.substring(1);
		IDao iDao = (IDao) MySpringUtil.getSpringComponent(springComponentName);
		logger.debug("offset:"+offset);
		logger.debug("limit:"+limit);
		return iDao.find(offset, limit);
		
		//return false;
	}

	

	public boolean submitPersistentEntities(List<MyBaseModel> list) {
		// TODO Auto-generated method stub
		return false;
	}
}*/
